<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<script type="text/javascript">
	
	var ctx = "<%=request.getContextPath()%>"; 
	
	function toggle(divid){
		
	}


	


	function locationWarehouseURL(id){
		if (id == "") {
			return;
		}
		var url =  ctx + '/warehouse/stock/waresearch/' + id + '/view';
		window.location = url;
	}
	
	function doDelteNormalValidate(confirmMsg , errorMsg , EntityName , tmpKey , object , indentUrl){

		if (window.confirm(confirmMsg)) {
			var parameters = "entity=" + EntityName + '&key=' + tmpKey + '&value=' + object;
			var myAjax = new Ajax.Request(
					url = ctx+'/common/delete/normal', // 请求的URL
					{
		                method: 'post', // 使用POST方式发送HTTP请求
		                parameters : parameters,
		                onComplete: showMessageValidate // 指定请求成功完成时需要执行的方法
		            }
		
		        );
		}


		function showMessageValidate(request) {
			if(request.responseText == 'true'){
				window.location = indentUrl;
			}else {
				alert(errorMsg);
			}
	    }
		
	}

	function doDelteObjectValidate(confirmMsg , errorMsg , EntityName , tmpKey , object , indentUrl){

		if (window.confirm(confirmMsg)) {
			var parameters = "entity=" + EntityName + '&key=' + tmpKey + '&value=' + object;
			var myAjax = new Ajax.Request(
					url = ctx+'/common/delete/object', // 请求的URL
					{
		                method: 'post', // 使用POST方式发送HTTP请求
		                parameters : parameters,
		                onComplete: showMessage // 指定请求成功完成时需要执行的方法
		            }
		
		        );
		}


		function showMessage(request) {
			if(request.responseText == 'true'){
				window.location = indentUrl;
			}else {
				alert(errorMsg);
			}
	    }
		
	}
	
	function doDelete(confirmMsg , sourceUrl){
		if (window.confirm(confirmMsg)) {
			window.location=sourceUrl;
		}
	}

	function doDeleteAjax(confirmMsg , sourceUrl , indentUrl ){

		if (window.confirm(confirmMsg)) {
			var myAjax = new Ajax.Request(
					sourceUrl, // 请求的URL
					{
		                method: 'post', // 使用POST方式发送HTTP请求
		                onComplete: reLocation // 指定请求成功完成时需要执行的方法
		            }
		
		        );
		}
		
		function reLocation(request) {
			window.location=indentUrl;
	    }
	}

	function duplicateCheck(theForm,mode,sentence , tmpKey,tmpValue,errorMsg , checkComponent){
		
		var result = Validator.Validate(theForm, mode);
		if (result){
		if (!$(checkComponent).readOnly) {
			
				var object = $(tmpValue).value;
				url = ctx+'/common/duplicate';
				var myAjax = new Ajax.Request(
						url, // 请求的URL
						{
			                method: 'post', // 使用POST方式发送HTTP请求
			                parameters:'sqlSentence='+sentence + '&key=' + tmpKey + '&value=' + object,
			                onComplete: showResponseCheck // 指定请求成功完成时需要执行的方法
			            }
			
			
					);

				
			} else {
				theForm.submit();
			}
		}

		function showResponseCheck(request) {
			if (request.responseText == 'false') {
				theForm.submit();
			} else {
				alert(errorMsg);
			}
		}
	}

	function duplicate(theForm, mode, sentence, tmpKey, tmpValue, errorMsg) {

		var result = Validator.Validate(theForm, mode);
		if (result) {
			var object = $(tmpValue).value;
			url = ctx + '/common/duplicate';
			var myAjax = new Ajax.Request(url, // 请求的URL
					{
						method :'post', // 使用POST方式发送HTTP请求
						parameters :'sqlSentence=' + sentence + '&key='
								+ tmpKey + '&value=' + object,
						onComplete :showResponse
					// 指定请求成功完成时需要执行的方法
					}

			);
		}
		function showResponse(request) {
			if (request.responseText == 'false') {
				theForm.submit();
			} else {
				alert(errorMsg);
			}
		}
	}

	$$('*[display]').each(
			function(element) {
				if (!$w($(element).readAttribute('display')).include(
						'${currentUser.position}')) {
					$(element).remove();
				}
			});

	$$('*[edit]')
			.each(
					function(element) {
						if ($w($(element).readAttribute('edit')).include(
								'${currentUser.position}')
								&& !$(element).readAttribute('href').endsWith(
										'/edit')) {
							$(element).writeAttribute('href',
									$(element).readAttribute('href') + "/edit");
						}
					});

					
	function clearAll(v,name) 
		{ 
		   var el = document.getElementsByName(name); 
		   var len = el.length; 
		   for(var i=0; i<len; i++) 
	    	{ 
		       if((el[i].type=="checkbox") && (el[i].name==name)) 
		        { 
		           el[i].checked = v.checked; 
		        } 
		   } 
	} 
	function isSelected(name){
		var el = document.getElementsByName(name); 
		   var len = el.length;
		   var b = false; 
		   for(var i=0; i<len; i++) 
	    	{ 
		       if((el[i].type=="checkbox") && (el[i].name==name)) 
		        { 
			        if(el[i].checked == true){
		          		b =true;
		          		
			        }
		        } 
		   }
		   return b;
	}
	/**
	 * 根据名称，返回如1,2,3类似的值，中间以逗号分隔 
	 */
	function getValuesByTagName(name){
		var val = document.getElementsByName(name);
		var str ='';
		if(val){	
			for(var i=0,len = val.length;i<len;i++){
				if(val[i].checked){
					str += val[i].value+',';
				}
			}
			return str.substring(0,str.length-1);
		}
		return str;
	}
    /**验证上传的是
	否为excel文件*/
function checkFile(name){
	if($(name)){
		var parm = /xls$/;
		if($(name).value){
			if(parm.exec($(name).value)){
				return true;
			}
			else{
				alert('请选择excel文件！');
				return false;
			}
			return true;
		}else{
			alert('请选择文件！');
			return false;
		}
	}
}		
</script>
<script type="text/javascript" src="${ctx}/static/js/map.js"></script>
<script type="text/javascript" src="${ctx}/static/js/livepipe.js"></script>
<script type="text/javascript" src="${ctx}/static/js/resizable.js"></script>
<script type="text/javascript" src="${ctx}/static/js/window.js"></script>
<script type="text/javascript" src="${ctx}/static/js/json2.js"></script>
<script type="text/javascript" src="${ctx}/static/js/swfobject.js"></script>
<script type="text/javascript" src="${ctx}/static/js/pagination.js"></script>
<script type="text/javascript" src="${ctx}/static/js/protoaculous.1.8.1.min.js"></script>
<script type="text/javascript" src="${ctx}/static/js/demo2do-utils.js"></script>
<script type="text/javascript" src="${ctx}/static/js/validator.js"></script>